import axios from 'axios';
import type { DictType } from '~/types/Dict';

export const useDict = () => {
    const getDictTypePage = async (params: { pageNum: number, pageSize: number, dictName?: string, dictType?: string }) => {
        try {
            const response = await axios.get('/dict/type/page', { params });
            return response.data;
        } catch (error) {
            console.error('Failed to fetch dict type page', error);
        }
    };

    const addDictType = async (dictType: DictType) => {
        try {
            const response = await axios.post('/dict/type', dictType);
            return response.data;
        } catch (error) {
            console.error('Failed to add dict type', error);
        }
    };

    const updateDictType = async (dictType: DictType) => {
        try {
            const response = await axios.put('/dict/type', dictType);
            return response.data;
        } catch (error) {
            console.error('Failed to update dict type', error);
        }
    };

    const deleteDictType = async (id: number) => {
        try {
            const response = await axios.delete(`/dict/type/${id}`);
            return response.data;
        } catch (error) {
            console.error('Failed to delete dict type', error);
        }
    };

    return {
        getDictTypePage,
        addDictType,
        updateDictType,
        deleteDictType,
    };
}; 